package com.bw.ivideoproject.video


import android.view.WindowManager
import com.bw.ivideoproject.R
import com.bw.ivideoproject.databinding.ActivityVideoDetailBinding
import com.bw.ivideoproject.entity.VideoEntity
import com.bw.lib_mvvm.BaseActivity
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.SimpleExoPlayer

class VideoDetailActivity : BaseActivity<ActivityVideoDetailBinding>() {

    private var video:VideoEntity? = null
    private var player: SimpleExoPlayer?= null

    override fun initView() {
        video = intent.getSerializableExtra("video") as VideoEntity
        if(player == null){
            player = SimpleExoPlayer.Builder(this).build()
        }
        binding.exoPv.player = player
        val mediaItem = MediaItem.fromUri(video?.videopath!!)

        player?.setMediaItem(mediaItem)
        player?.prepare()
        player?.play()
    }

    override fun initData() {

    }

    override fun onStart() {
        super.onStart()
        binding.exoPv.onResume()
    }

    override fun onStop() {
        super.onStop()
        binding.exoPv.onPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        player?.release()
        player = null
    }

    override fun bindLayout(): Int {
        return R.layout.activity_video_detail
    }


    override fun onResume() {
        super.onResume()
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
    }

    override fun onPause()
    {
        super.onPause()
        window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
    }

}